package com.lswms.modules.lswms.service.impl.stock;

import java.util.List;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.lswms.common.page.PageData;
import com.lswms.common.service.impl.CrudServiceImpl;
import com.lswms.modules.lswms.dao.stock.LotDao;
import com.lswms.modules.lswms.dto.stock.LotDTO;
import com.lswms.modules.lswms.entity.stock.LotEntity;
import com.lswms.modules.lswms.service.stock.LotService;

/**
 * 属性
 *
 * @author DX sunlightcs@gmail.com
 * @since 1.0.0 2021-06-14
 */
@Service
public class LotServiceImpl extends CrudServiceImpl<LotDao, LotEntity, LotDTO> implements LotService {

	@Override
	public QueryWrapper<LotEntity> getWrapper(Map<String, Object> params) {
		String id = (String) params.get("id");
		String lot = (String) params.get("lot");
		String sku = (String) params.get("sku");
		String descr = (String) params.get("descr");

		QueryWrapper<LotEntity> wrapper = new QueryWrapper<>();
		wrapper.eq(StringUtils.isNotBlank(id), "id", id);
		wrapper.eq(StringUtils.isNotBlank(lot), "lot", lot);
		wrapper.eq(StringUtils.isNotBlank(sku), "lswms_sku.sku", sku);
		wrapper.like(StringUtils.isNotBlank(descr), "descr", descr);

		wrapper.orderByDesc("lot");
		return wrapper;
	}

	@Override
	public PageData<LotEntity> pageBySql(Map<String, Object> params) {
		IPage<LotEntity> page = baseDao.selectPageBySql(getPage(params, null, false), getWrapper(params));
		return getPageData(page, LotEntity.class);
	}

	@Override
	public List<LotEntity> ByLotN(Map<String, Object> params) {
		String id = (String) params.get("id");
		String lot = (String) params.get("lot");
		String sku = (String) params.get("sku");
		Object lot1 = (String) params.get("lot1");
		Object lot2 = (String) params.get("lot2");
		String lot3 = (String) params.get("lot3");
		String lot4 = (String) params.get("lot4");
		String lot5 = (String) params.get("lot5");
		String lot6 = (String) params.get("lot6");
		String lot7 = (String) params.get("lot7");
		String lot8 = (String) params.get("lot8");
		String lot9 = (String) params.get("lot9");
		String lot10 = (String) params.get("lot10");	
		String lot11 = (String) params.get("lot11");
		String lot12 = (String) params.get("lot12");
		String lot13 = (String) params.get("lot13");
		String lot14 = (String) params.get("lot14");
		String lot15 = (String) params.get("lot15");

		


		QueryWrapper<LotEntity> wrapper = new QueryWrapper<>();
		wrapper.eq(StringUtils.isNotBlank(id), "id", id);
		wrapper.eq(StringUtils.isNotBlank(lot), "lot", lot);
		wrapper.eq(StringUtils.isNotBlank(sku), "sku", sku);
		wrapper.eq(lot1!=null, "lot1", lot1);
		wrapper.eq(lot2!=null, "lot2", lot2);
		wrapper.eq(StringUtils.isNotBlank(lot3), "lot3", lot3);
		wrapper.eq(StringUtils.isNotBlank(lot4), "lot4", lot4);
		wrapper.eq(StringUtils.isNotBlank(lot5), "lot5", lot5);
		wrapper.eq(StringUtils.isNotBlank(lot6), "lot6", lot6);
		wrapper.eq(StringUtils.isNotBlank(lot7), "lot7", lot7);
		wrapper.eq(StringUtils.isNotBlank(lot8), "lot8", lot8);
		wrapper.eq(StringUtils.isNotBlank(lot9), "lot9", lot9);
		wrapper.eq(StringUtils.isNotBlank(lot10), "lot10", lot10);
		wrapper.eq(StringUtils.isNotBlank(lot11), "lot11", lot11);
		wrapper.eq(StringUtils.isNotBlank(lot12), "lot12", lot12);
		wrapper.eq(StringUtils.isNotBlank(lot13), "lot13", lot13);
		wrapper.eq(StringUtils.isNotBlank(lot14), "lot14", lot14);
		wrapper.eq(StringUtils.isNotBlank(lot15), "lot15", lot15);
		wrapper.orderByDesc("lot");
		List<LotEntity> list = baseDao.selectList(wrapper) ;
		
		
		return list;
	}

}